<template>

    <div class="section-header">
      <div class="title-section">
        <h2 class="main-title">最新求购</h2>
        <span class="sub-title">Latest purchasing request</span>
      </div>
      <el-button type="primary" link class="view-more" @click="genduo">查看更多</el-button>
    </div>

  <div class="card-container">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="(item, index) in cardList.slice(0,8)" :key="index">
        <el-card class="card-item" shadow="hover">
          <template #header>
            <div class="card-header">
              <span>{{ item.typeName }}型号{{ item.model }}</span>
            </div>
          </template>
          
    
          
          <div class="card-content">
            <div class="card-info">
              <div class="info-item">
                <el-icon></el-icon>
                <span>{{ item.contactName }}</span>
              </div>
              <div class="info-item">
                <el-icon><Phone /></el-icon>
                <span>{{ item.contactPhone }}</span>
              </div>
              <div class="info-item">
                <el-icon><Calendar /></el-icon>
                <span>{{ item.expectedYear }}年</span>
              </div>
            </div>
            
            <div class="price">{{ item.expectedPrice }}元</div>
            
            <div class="card-footer">
              <el-button type="primary" size="small" @click="handleDetail(item)">查看详情</el-button>
              <el-button type="success" size="small" @click="handleContact(item)">联系客服</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
  <el-dialog v-model="dialogVisible9" title="业务员信息" width="30%">
              <el-card shadow="hover">
                <el-descriptions :column="1">
                  <el-descriptions-item label="业务员ID">
                    <el-tag type="info">#{{ pur.businessmanId }}</el-tag>
                  </el-descriptions-item>
                  <el-descriptions-item label="业务员姓名">
                    <span class="highlight-text">{{ pur.name }}</span>
                  </el-descriptions-item>
                  <el-descriptions-item label="手机号">
                    <span class="highlight-text">{{ pur.phone }}</span>
                  </el-descriptions-item>
                </el-descriptions>
              </el-card>
              <template #footer>
                <el-button type="primary" @click="dialogVisible9 = false">关闭</el-button>
              </template>
              </el-dialog>
</template>

<script setup>
import { onMounted,ref } from 'vue';
import axios from 'axios'
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
import {useCounterStore} from '@/stores/counter'
const router = useRouter()
const dialogVisible9 = ref(false)


import {
  User,
  Phone,
  Calendar
} from '@element-plus/icons-vue'
onMounted(() => {
  getCardData()
})
const genduo = () => {
  router.push('/qiugou1')
}
const getCardData = async () => {
  try {
    
    const res = await axios.get('advertisement/selectFour')
    console.log("llll",res.data.data.list)
    cardList.value = res.data.data.list
  } catch (error) {
    console.error("获取案例数据失败:", error)
  }
}

// 模拟数据
const cardList = ref([])

// 状态类型映射
const getStatusType = (status) => {
  const types = ['warning', 'primary', 'success', 'danger']
  return types[status] || 'info'
}

// 状态文本映射
const getStatusText = (status) => {
  const texts = ['待处理', '已分配', '已成交', '已取消']
  return texts[status] || '未知状态'
}

// 查看详情
const handleDetail = (item) => {
  useCounterStore().purchaseData=item
  useCounterStore().purchaseData.contactPhone = (item.contactPhone.replace(
    /(\d{3})\d{4}(\d{4})/,
    "$1****$2"
  )
  )
  router.push({
    name: 'test',
  });
}
const pur = ref({})
// 联系买家
const handleContact =async (item) => {
   if (useCounterStore().token==null || useCounterStore().token=='') {
    alert('请先登录')
    ElMessage.warning('请先登录')
  }else{
  dialogVisible9.value = true
    const res = await axios.get(`eduservice/businessman/${item.businessmanId}`)
   pur.value=res.data.data.businessman
  }
}
</script>

<style scoped>
.card-container {
  padding: 20px;
  background: #f5f5f5;
}

.card-item {
  margin-bottom: 20px;
  transition: all 0.3s;
}

.card-item:hover {
  transform: translateY(-5px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  margin-bottom: 10px;
}

.card-content {
  padding: 10px 0;
}

.card-info {
  margin-bottom: 10px;
}

.info-item {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  font-size: 14px;
  color: #666;
}

.info-item .el-icon {
  margin-right: 5px;
  color: #1890ff;
}

.price {
  font-size: 18px;
  font-weight: bold;
  color: #ff4d4f;
  margin: 10px 0;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 15px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .card-image {
    height: 150px;
  }
}
.transaction-cases {
  max-width: 100%;
  margin: 0 auto;
  padding: 40px 20px;
  background: #f5f5f5;
}

/* 标题区域样式 */
.section-header {
  background: #f5f5f5;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 30px;
  border-bottom: 2px solid #409EFF;
  padding-bottom: 10px;
}

.title-section {
  display: flex;
  align-items: baseline;
  gap: 15px;
}


</style>